package com.baichang.taoshunda.controller.web.business;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.service.BusinessService;
import com.baichang.taoshunda.service.BussMsgService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@Controller
@RequestMapping(ControllerConstants.BUSINESSREGISTER)
public class BussinessRegisterController  extends BaseMobileController {

    @Autowired
    private BusinessService businessService;
    @Autowired
    private BussMsgService bussMsgService;

    /**
     * 邀请商家注册，商家注册请求
     *
     * @param request
     * @param response
     */
    @RequestMapping("/businessRegister")
    @ResponseBody
    public void findPushList(HttpServletRequest request, HttpServletResponse response) throws ServiceException, IOException {
        response.setContentType("text/html;charset=utf-8");
        response.setHeader("Content-type", "application/json;charset=utf-8");
        Integer userId =Integer.valueOf(request.getParameter("userId"));
        String phone = request.getParameter("phone");
        String password =request.getParameter("password");
        String verification_code =request.getParameter("verification_code");
        Integer registerNumber=1;
        Map<String, Object> ret=  bussMsgService.checkCodeMsg(phone,verification_code)?businessService.businessregister(phone,verification_code,password,userId, registerNumber):null;
        response.getWriter().print(JSONObject.fromObject(ret));
    }


    /**
     * 获取注册时候的验证码
     *
     * @param request
     * @param response
     */
    @RequestMapping("/getRegisterMsg")
    @ResponseBody
    public void getRegisterMsg(HttpServletRequest request, HttpServletResponse response) throws ServiceException, IOException {
        response.setContentType("text/html;charset=utf-8");
        response.setHeader("Content-type", "application/json;charset=utf-8");
        String mobile = request.getParameter("mobile");
        response.getWriter().print(bussMsgService.getRegisterMsg(mobile));
    }

}
